package cn.kgc.spring.service;

import cn.kgc.spring.entity.User;
import cn.kgc.spring.mapper.UserMapper;
import cn.kgc.spring.mapper.UserMapperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author: mosin
 * @version: v1.0  2022/7/1
 *   @Service  注解 标记类纳入spring容器的管理  没有指定key  那么默认的key 是类名首字母的小写 userServiceImpl
 *    如果指定了key  则获取是要是用指定的key
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    /*
        @Autowired  默认根据类型注入   byType
        在注入属性值时 发现多于一个符合要求的bean实例，那么spring容器会尝试
        在spring容器中寻找和属性名一致的id 作为注入的值  byName
        推荐使用
     */

    @Autowired
    @Qualifier("userMapperImpl2")
    private UserMapper userMapper;

    // javax.annotation.Resource;
    //@Resource(name = "userMapperImpl2")
    //private UserMapper userMapper;

    //@Autowired
    //@Qualifier("userMapperImpl2")
    //public void setUserMapper(UserMapper userMapper) {
    //    System.out.println("setUserMapper()");
    //    this.userMapper = userMapper;
    //}

    @Override
    public Boolean login(User user) {

        User login = userMapper.login(user);
        return login == null;
    }
}
